﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public static class Utils
{
    /// <summary>
    /// 球半径
    /// </summary>
    /// <param name="posA"></param>
    /// <param name="posB"></param>
    /// <param name="posC"></param>
    /// <returns>vector3 (x,y)是圆心位置，z是半径</returns>
    public static Vector3 CalRadius(Vector2 posA, Vector2 posB, Vector2 posC)
    {
        float x1, y1, x2, y2, x3, y3;
        float a, b, c, g, e, f;
        x1 = posA.x;
        y1 = posA.y;
        x2 = posB.x;
        y2 = posB.y;
        x3 = posC.x;
        y3 = posC.y;
        e = 2 * (x2 - x1);
        f = 2 * (y2 - y1);
        g = x2 * x2 - x1 * x1 + y2 * y2 - y1 * y1;
        a = 2 * (x3 - x2);
        b = 2 * (y3 - y2);
        c = x3 * x3 - x2 * x2 + y3 * y3 - y2 * y2;
        float X = (g * b - c * f) / (e * b - a * f);
        float Y = (a * g - c * e) / (a * f - b * e);
        return new Vector3(X, Y, Mathf.Sqrt((X - x1) * (X - x1) + (Y - y1) * (Y - y1)));
    }
    
    /// <summary>
    /// 角度
    /// </summary>
    /// <param name="posA"></param>
    /// <param name="posB"></param>
    /// <param name="posC"></param>
    /// <returns></returns>
    public static Vector3 CalAngles(Vector2 posA, Vector2 posB, Vector2 posC)
    {
        float angleA = Vector2.Angle(posB - posA, posC - posA);
        float angleB = Vector2.Angle(posA - posB, posC - posB);
        float angleC = Vector2.Angle(posA - posC, posB - posC);
        return new Vector3(angleA, angleB, angleC);
    }

	public static Vector3 CalDistance(Vector2 posA, Vector2 posB, Vector2 posC)
	{
		float angleA = Vector2.Distance(posA, posB);
		float angleB = Vector2.Distance(posA, posC);
		float angleC = Vector2.Distance(posB, posC);
		return new Vector3(angleA, angleB, angleC);
	}
}
